import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../components/Login";
import Movies from "../components/page/Movies";
import Index from "../components/page/Index";
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Login',
    component: Login,
    meta:{title:'登录',requireAuth:true}
  },
  {
    path: '/index',
    name:'Home',
    component:() => import('../components/common/Home') ,
    meta: {title: '系统首页'},
    children:[
      {
        path: '/index',
        component: Index,
        meta: { title: '系统首页' }
      },
      {
        path: '/message',
        component: () => import('../components/page/Tabs'),
        meta: { title: '消息通知' }
      },
      {
        path:'/movie',
        name:'Movies',
        component:Movies,
        meta:{title:'电影管理'}
      },
      {
        path:'/roles',
        name:'Roles',
        component:() => import('../components/page/Roles'),
        meta:{title:'角色管理'}
      },
      {
        path:'/user',
        name:'UserManagement',
        component:() => import('../components/page/UserManagement'),
        meta:{title:'用户管理'}
      },
      {
        path:'/userAuth',
        name:'UserAuth',
        component:() => import('../components/page/UserAuth'),
        meta:{title:'权限管理'}
      },
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  routes
})
/*路由发生变化修改页面title的名称*/
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next();
})
export default router
